﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System.Collections;
using ThoughtWorks;
using ThoughtWorks.QRCode;
using ThoughtWorks.QRCode.Codec;
using ThoughtWorks.QRCode.Codec.Data;

namespace TS_XY_Train_Repaire.Locomotive.TrainRepair.Work.Datacomplete
{
    public partial class Locomotive_BodieRepair_Work_DataComplete_PersonWork_Form : DevExpress.XtraEditors.XtraForm
    {
        string _LoadWorkType = "1";
        public Locomotive_BodieRepair_Work_DataComplete_PersonWork_Form()
        {
            InitializeComponent();
        }

        private void Locomotive_BodieRepair_Work_DataComplete_PersonWork_Form_Load(object sender, EventArgs e)
        {
            this.repositoryItemButtonEdit2.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(this.repositoryItemButtonEdit1ButtonClick);
            _LoadWorkList("0,1");
        }
        private void _LoadWorkList(string _State)
        {
            string _Up = "-1";
            try
            {
                _Up = tl_Main.FocusedNode.ParentNode["f_id"].ToString();
                if (_Up.Substring(1,1)!="S")
                {
                    _Up = tl_Main.FocusedNode.ParentNode.ParentNode["f_id"].ToString();
                    if (_Up.Substring(1, 1) != "S")
                    {
                        _Up = tl_Main.FocusedNode.ParentNode.ParentNode["f_id"].ToString();

                    }
                }
            }
            catch { }
            TR_BU_Work_DataComplete_List _tl = new TR_BU_Work_DataComplete_List();
            tl_Main.Nodes.Clear();
            ArrayList pList = new ArrayList();
            _tl = new TR_BU_Work_DataComplete_List();
            _tl.f_id = "4";
            _tl.f_name = "自检作业";
            _tl.f_type = "";
            _tl.f_count = TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0", "f_count");
            pList.Add(_tl);
            _tl = new TR_BU_Work_DataComplete_List();
            _tl.f_id = "5";
            _tl.f_name = "互检作业";
            _tl.f_type = "";
            _tl.f_count = TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0", "f_count");
            pList.Add(_tl);
            _tl = new TR_BU_Work_DataComplete_List();
            _tl.f_id = "6";
            _tl.f_name = "专检作业";
            _tl.f_type = "";
            _tl.f_count = TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0", "f_count");
            pList.Add(_tl);
            _tl = new TR_BU_Work_DataComplete_List();
            _tl.f_id = "7";
            _tl.f_name = "抽检作业";
            _tl.f_type = "";
            _tl.f_count = TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0", "f_count");
            pList.Add(_tl);
            string strSQL = "select f_id,f_ttname+f_name+' '+(select f_name from TS_S_T_P_Train_RP where f_id=TS_TR_BU_Work_Main.f_rpid) as f_name,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwid=TS_TR_BU_Work_Main.f_id) and f_del=0) as f_count from TS_TR_BU_Work_Main where f_del=0 and f_id in (select f_bmwid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0)) and f_type=" + _LoadWorkType + "";
            SqlConnection conn = new SqlConnection(TS_Win_Class.GetSQlConnStr());
            conn.Open();
            SqlCommand cmd = new SqlCommand(strSQL, conn);
            SqlDataReader read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "4M" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_parent = "4";
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_ttname+f_name+' '+(select f_name from TS_S_T_P_Train_RP where f_id=TS_TR_BU_Work_Main.f_rpid) as f_name,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwid=TS_TR_BU_Work_Main.f_id) and f_del=0) as f_count from TS_TR_BU_Work_Main where f_id in (select f_bmwid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 and f_type=" + _LoadWorkType + " order by f_ttname,f_name asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "5M" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_parent = "5";
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_ttname+f_name+' '+(select f_name from TS_S_T_P_Train_RP where f_id=TS_TR_BU_Work_Main.f_rpid) as f_name,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwid=TS_TR_BU_Work_Main.f_id) and f_del=0) as f_count from TS_TR_BU_Work_Main where f_id in (select f_bmwid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 and f_type=" + _LoadWorkType + " order by f_ttname,f_name asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "6M" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_parent = "6";
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_ttname+f_name+' '+(select f_name from TS_S_T_P_Train_RP where f_id=TS_TR_BU_Work_Main.f_rpid) as f_name,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwid=TS_TR_BU_Work_Main.f_id) and f_del=0) as f_count from TS_TR_BU_Work_Main where f_id in (select f_bmwid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 and f_type=" + _LoadWorkType + " order by f_ttname,f_name asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "7M" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_parent = "7";
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwdid=TS_TR_BU_Work_Main_Day.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Day.f_state)) as f_color from TS_TR_BU_Work_Main_Day where f_id in (select f_bmwdid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "4D" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "序";
                _tl.f_parent = "4M" + read["f_bmwid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwdid=TS_TR_BU_Work_Main_Day.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Day.f_state)) as f_color from TS_TR_BU_Work_Main_Day where f_id in (select f_bmwdid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "5D" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "序";
                _tl.f_parent = "5M" + read["f_bmwid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwdid=TS_TR_BU_Work_Main_Day.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Day.f_state)) as f_color from TS_TR_BU_Work_Main_Day where f_id in (select f_bmwdid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "6D" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "序";
                _tl.f_parent = "6M" + read["f_bmwid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwdid=TS_TR_BU_Work_Main_Day.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Day.f_state)) as f_color from TS_TR_BU_Work_Main_Day where f_id in (select f_bmwdid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "7D" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "序";
                _tl.f_parent = "7M" + read["f_bmwid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwsid=TS_TR_BU_Work_Main_Steps.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Steps.f_state)) as f_color from TS_TR_BU_Work_Main_Steps where f_id in (select f_bmwsid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "4S" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "步";
                _tl.f_parent = "4D" + read["f_bmwdid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwsid=TS_TR_BU_Work_Main_Steps.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Steps.f_state)) as f_color from TS_TR_BU_Work_Main_Steps where f_id in (select f_bmwsid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "5S" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "步";
                _tl.f_parent = "5D" + read["f_bmwdid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwsid=TS_TR_BU_Work_Main_Steps.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Steps.f_state)) as f_color from TS_TR_BU_Work_Main_Steps where f_id in (select f_bmwsid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "6S" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "步";
                _tl.f_parent = "6D" + read["f_bmwdid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwsid=TS_TR_BU_Work_Main_Steps.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Steps.f_state)) as f_color from TS_TR_BU_Work_Main_Steps where f_id in (select f_bmwsid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "7S" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "步";
                _tl.f_parent = "7D" + read["f_bmwdid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwgid=TS_TR_BU_Work_Main_Group.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group.f_state)) as f_color from TS_TR_BU_Work_Main_Group where f_id in (select f_bmwgid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "4G" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "组";
                _tl.f_parent = "4S" + read["f_bmwsid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwgid=TS_TR_BU_Work_Main_Group.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group.f_state)) as f_color from TS_TR_BU_Work_Main_Group where f_id in (select f_bmwgid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "5G" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "组";
                _tl.f_parent = "5S" + read["f_bmwsid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwgid=TS_TR_BU_Work_Main_Group.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group.f_state)) as f_color from TS_TR_BU_Work_Main_Group where f_id in (select f_bmwgid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "6G" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "组";
                _tl.f_parent = "6S" + read["f_bmwsid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,(select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_rid in (select f_id from TS_TR_BU_Work_Main_Group_WorkPlace where f_bmwgid=TS_TR_BU_Work_Main_Group.f_id) and f_del=0) as f_count,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group.f_state)) as f_color from TS_TR_BU_Work_Main_Group where f_id in (select f_bmwgid from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "7G" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "组";
                _tl.f_parent = "7S" + read["f_bmwsid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,f_bmwgid,1 as f_count,f_brief,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group_WorkPlace.f_state)) as f_color from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=4 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "4W" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_bmwgid"].ToString();
                _tl.f_bmwwpid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_brief = read["f_brief"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "项";
                _tl.f_parent = "4G" + read["f_bmwgid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,f_bmwgid,1 as f_count,f_brief,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group_WorkPlace.f_state)) as f_color from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=5 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "5W" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_bmwgid"].ToString();
                _tl.f_bmwwpid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_brief = read["f_brief"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "项";
                _tl.f_parent = "5G" + read["f_bmwgid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,f_bmwgid,1 as f_count,f_brief,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group_WorkPlace.f_state)) as f_color from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=6 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "6W" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_bmwgid"].ToString();
                _tl.f_bmwwpid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_brief = read["f_brief"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "项";
                _tl.f_parent = "6G" + read["f_bmwgid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            strSQL = "select f_id,f_name,f_bmwid,f_bmwdid,f_bmwsid,f_bmwgid,1 as f_count,f_brief,(select f_string from TS_S_T_S_ColorList where f_id=(select f_cid from TS_S_T_S_RP_DataState where f_id=TS_TR_BU_Work_Main_Group_WorkPlace.f_state)) as f_color from TS_TR_BU_Work_Main_Group_WorkPlace where f_id in (select f_rid from TS_TR_BU_Work_Main_Relation where f_rtype=7 and f_ftype=0 and f_type=" + _LoadWorkType + " and f_state in (" + _State + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_del=0) and f_del=0 order by f_order asc";
            cmd = new SqlCommand(strSQL, conn);
            read = cmd.ExecuteReader();
            while (read.Read())
            {
                _tl = new TR_BU_Work_DataComplete_List();
                _tl.f_id = "7W" + read["f_id"].ToString();
                _tl.f_bmwid = read["f_bmwid"].ToString();
                _tl.f_bmwdid = read["f_bmwdid"].ToString();
                _tl.f_bmwsid = read["f_bmwsid"].ToString();
                _tl.f_bmwgid = read["f_bmwgid"].ToString();
                _tl.f_bmwwpid = read["f_id"].ToString();
                _tl.f_name = read["f_name"].ToString();
                _tl.f_brief = read["f_brief"].ToString();
                _tl.f_count = read["f_count"].ToString();
                _tl.f_color = read["f_color"].ToString();
                _tl.f_type = "项";
                _tl.f_parent = "7G" + read["f_bmwgid"].ToString();
                pList.Add(_tl);
            }
            read.Close();
            conn.Close();
            conn.Dispose(); tl_Main.DataSource = pList;
            tl_Main.SetFocusedNode(tl_Main.FindNodeByFieldValue("f_id", _Up));
            //tl_Main.ExpandAll();        
        }
        private void repositoryItemButtonEdit1ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            //DevExpress.XtraGrid.Views.Grid.GridView view = ((DevExpress.XtraGrid.Views.Grid.GridView)(gc_Main.MainView));
            string strSQL = "";
            if (!cb_0.Checked)
            {
                switch (tl_Main.FocusedNode["f_id"].ToString().Substring(0, 1))
                {
                    case "4":
                        if (tl_Main.FocusedNode["f_id"].ToString() != "4")
                        {
                            switch (tl_Main.FocusedNode["f_id"].ToString().Substring(1, 1))
                            {
                                case "M":
                                    MessageBox.Show("完成机车" + tl_Main.FocusedNode["f_name"].ToString() + "所有自检项目");
                                    break;
                                case "D":
                                    if (MessageBox.Show("确定完成工序 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的自检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_w in _no_s.Nodes)
                                                {
                                                    _strID += _no_w["f_id"].ToString().Substring(2) + ",";
                                                }
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=4 and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time0=getdate(),f_result='合格' where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "S":
                                    if (MessageBox.Show("确定完成工步 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的自检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                _strID += _no_s["f_id"].ToString().Substring(2) + ",";
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=4 and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time0=getdate(),f_result='合格' where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "G":
                                    if (MessageBox.Show("确定完成作业组 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的自检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            _strID += _no["f_id"].ToString().Substring(2)+ ",";
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=4 and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time0=getdate(),f_result='合格' where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "W":
                                    if (MessageBox.Show("确定完成项点 " + tl_Main.FocusedNode["f_name"].ToString() + "自检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=4 and f_ftype=0 and f_rid=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2) + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time0=getdate(),f_result='合格' where f_id=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2);
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                            }
                        }
                        break;
                    case "5":
                        if (tl_Main.FocusedNode["f_id"].ToString() != "5")
                        {
                            switch (tl_Main.FocusedNode["f_id"].ToString().Substring(1, 1))
                            {
                                case "M":
                                    MessageBox.Show("完成机车" + tl_Main.FocusedNode["f_name"].ToString() + "所有互检项目");
                                    break;
                                case "D":
                                    if (MessageBox.Show("确定完成工序 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的互检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_w in _no_s.Nodes)
                                                {
                                                    _strID += _no_w["f_id"].ToString().Substring(2) + ",";
                                                }
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        if (TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype in (4) and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)", "f_count") == "0")
                                        {
                                            strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=5 and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)";
                                            strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid1=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time1=getdate() where f_id in (" + _strID + ")";
                                            TS_Win_Class.MySqlCom(strSQL);
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                            {
                                                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                                {
                                                    foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_w in _no_s.Nodes)
                                                    {
                                                        TS_Win_Class._AutoSumWorkMainDataFinish("W", _no_w["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                                    }
                                                }
                                            }
                                            //TS_Win_Class._AutoSumWorkMainDataFinish("G", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                        }
                                        else
                                        {
                                            MessageBox.Show("作业工序下有项点自检作业尚未完工，不能完成批量互检作业确认！！");
                                        }
                                    }
                                    break;
                                case "S":
                                    if (MessageBox.Show("确定完成工步 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的互检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                _strID += _no_s["f_id"].ToString().Substring(2) + ",";
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        if (TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype in (4) and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)", "f_count") == "0")
                                        {
                                            strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=5 and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)";
                                            strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid1=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time1=getdate() where f_id in (" + _strID + ")";
                                            TS_Win_Class.MySqlCom(strSQL);
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                            {
                                                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                                {
                                                    TS_Win_Class._AutoSumWorkMainDataFinish("W", _no_s["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                                }
                                            }
                                            //TS_Win_Class._AutoSumWorkMainDataFinish("G", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                        }
                                        else
                                        {
                                            MessageBox.Show("作业工步下有项点自检作业尚未完工，不能完成批量互检作业确认！！");
                                        }
                                    }
                                    break;
                                case "G":
                                    if (MessageBox.Show("确定完成作业组 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的互检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            _strID += _no["f_id"].ToString().Substring(2) + ",";
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        if (TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype in (4) and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)", "f_count") == "0")
                                        {
                                            strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=5 and f_ftype=0 and f_rid in (" + _strID + ") and f_state in (0,1)";
                                            strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid1=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time1=getdate() where f_id in (" + _strID + ")";
                                            TS_Win_Class.MySqlCom(strSQL);
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                            {
                                                TS_Win_Class._AutoSumWorkMainDataFinish("W", _no["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                            }
                                            //TS_Win_Class._AutoSumWorkMainDataFinish("G", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                        }
                                        else
                                        {
                                            MessageBox.Show("作业组下有项点自检作业尚未完工，不能完成批量互检作业确认！！");
                                        }
                                    }
                                    break;
                                case "W":
                                    if (MessageBox.Show("确定完成项点 " + tl_Main.FocusedNode["f_name"].ToString() + "互检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        //判断项点对应的自检工单是否全部完工
                                        if (TS_Win_Class.GetSQlFieldValue("select count(*) as f_count from TS_TR_BU_Work_Main_Relation where f_rtype in (4) and f_ftype=0 and f_rid=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2) + " and f_state in (0,1)", "f_count") == "0")
                                        {
                                            strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9 ,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=5 and f_ftype=0 and f_rid=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2) + " and f_state in (0,1)";
                                            strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_stuffid1=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_time1=getdate() where f_id=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2);
                                            TS_Win_Class.MySqlCom(strSQL);
                                            TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                        }
                                        else
                                        {
                                            MessageBox.Show("自检作业尚未完工，不能完成互检作业！！");
                                        }
                                    }
                                    break;
                            }
                        }
                        break;
                    case "6":
                        if (tl_Main.FocusedNode["f_id"].ToString() != "6")
                        {
                            switch (tl_Main.FocusedNode["f_id"].ToString().Substring(1, 1))
                            {
                                case "M":
                                    MessageBox.Show("完成机车" + tl_Main.FocusedNode["f_name"].ToString() + "所有互检项目");
                                    break;
                                case "D":
                                    if (MessageBox.Show("确定完成工序 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的互检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_w in _no_s.Nodes)
                                                {
                                                    _strID += _no_w["f_id"].ToString().Substring(2) + ",";
                                                }
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=6 and f_ftype=0 and f_rid in (" + _strID + ") and f_fid="+TS_Win_Locomotive_MainForm.pUserInfoMain.GuId+" and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time2=getdate() where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "S":
                                    if (MessageBox.Show("确定完成工步 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的专检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                _strID += _no_s["f_id"].ToString().Substring(2) + ",";
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=6 and f_ftype=0 and f_rid in (" + _strID + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time2=getdate() where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "G":
                                    if (MessageBox.Show("确定完成作业组 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的专检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            _strID += _no["f_id"].ToString().Substring(2) + ",";
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=6 and f_ftype=0 and f_rid in (" + _strID + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time2=getdate() where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "W":
                                    if (MessageBox.Show("确定完成项点 " + tl_Main.FocusedNode["f_name"].ToString() + "专检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=6 and f_ftype=0 and f_rid=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2) + " and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time2=getdate() where f_id=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2);
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                            }
                        }
                        break;
                    case "7":
                        if (tl_Main.FocusedNode["f_id"].ToString() != "7")
                        {
                            switch (tl_Main.FocusedNode["f_id"].ToString().Substring(1, 1))
                            {
                                case "M":
                                    MessageBox.Show("完成机车" + tl_Main.FocusedNode["f_name"].ToString() + "所有抽检项目");
                                    break;
                                case "D":
                                    if (MessageBox.Show("确定完成工序 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的抽检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_w in _no_s.Nodes)
                                                {
                                                    _strID += _no_w["f_id"].ToString().Substring(2) + ",";
                                                }
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=7 and f_ftype=0 and f_rid in (" + _strID + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time3=getdate() where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "S":
                                    if (MessageBox.Show("确定完成工步 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的抽检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no_s in _no.Nodes)
                                            {
                                                _strID += _no_s["f_id"].ToString().Substring(2) + ",";
                                            }
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=7 and f_ftype=0 and f_rid in (" + _strID + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time3=getdate() where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "G":
                                    if (MessageBox.Show("确定完成作业组 " + tl_Main.FocusedNode["f_name"].ToString() + " 所有项点的抽检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        string _strID = "";
                                        foreach (DevExpress.XtraTreeList.Nodes.TreeListNode _no in tl_Main.FocusedNode.Nodes)
                                        {
                                            _strID += _no["f_id"].ToString().Substring(2) + ",";
                                        }
                                        _strID = _strID.Substring(0, _strID.Length - 1);
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=7 and f_ftype=0 and f_rid in (" + _strID + ") and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time3=getdate() where f_id in (" + _strID + ")";
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                                case "W":
                                    if (MessageBox.Show("确定完成项点 " + tl_Main.FocusedNode["f_name"].ToString() + "抽检作业吗？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
                                    {
                                        strSQL = "update TS_TR_BU_Work_Main_Relation set f_state=9,f_estuffid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + ",f_etime=getdate() where f_rtype=7 and f_ftype=0 and f_rid=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2) + " and f_fid=" + TS_Win_Locomotive_MainForm.pUserInfoMain.GuId + " and f_state in (0,1)";
                                        strSQL += ";update TS_TR_BU_Work_Main_Group_WorkPlace set f_time3=getdate() where f_id=" + tl_Main.FocusedNode["f_id"].ToString().Substring(2);
                                        TS_Win_Class.MySqlCom(strSQL);
                                        //TS_Win_Class._AutoSumWorkMainDataFinish("W", tl_Main.FocusedNode["f_id"].ToString().Substring(2), TS_Win_Locomotive_MainForm.pUserInfoMain.GuId);
                                    }
                                    break;
                            }
                        }
                        break;
                }
                if (cb_0.Checked)
                {
                    cb_0.Text = "已完工作业数据";
                    _LoadWorkList("9");
                }
                else
                {
                    cb_0.Text = "未完工作业数据";
                    _LoadWorkList("0,1");
                }
            }
            //MessageBox.Show(tl_Main.FocusedNode["f_name"].ToString());
        }

        private void Locomotive_BodieRepair_Work_DataComplete_PersonWork_Form_FormClosing(object sender, FormClosingEventArgs e)
        {
            TS_Win_Locomotive_MainForm.htActionItem.Remove(this.Name);
        }

        private void cb_0_CheckedChanged(object sender, EventArgs e)
        {
            if (cb_0.Checked)
            {
                cb_0.Text = "已完工作业数据";
                _LoadWorkList("9");
            }
            else
            {
                cb_0.Text = "未完工作业数据";
                _LoadWorkList("0,1");
            }
        }

        private void bt_Expro_Click(object sender, EventArgs e)
        {
            //tl_Main.ExportToXlsx(TS_Win_Class._EXP_Direct+TS_Win_Locomotive_MainForm.pUserInfoMain.Username+"导出作业数据.xlsx");
            //MessageBox.Show("文件导出为   " + TS_Win_Class._EXP_Direct + TS_Win_Locomotive_MainForm.pUserInfoMain.Username + "导出作业数据.xlsx");
        }
    }
}